﻿Imports System.Data.OleDb
Public Class Recipe
    Inherits System.Web.UI.Page
    Const RATING1_MIN As Integer = 1
    Const RATING1_MAX As Integer = 6

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then
            Try
                UpdateRep(False)
            Catch ex As Exception

            End Try
        End If

        
    End Sub
    Protected Sub Rating1_Changed(sender As Object, e As AjaxControlToolkit.RatingEventArgs)

        Try
            ' cast rating control which has initiated the call:
            Dim myRating As AjaxControlToolkit.Rating = DirectCast(sender, AjaxControlToolkit.Rating)
            ' regular expression which will help identifying row number: 
            Dim rexLineNo As New System.Text.RegularExpressions.Regex("ctl\d+")

            Dim dbcurrent As Double = Convert.ToDouble(e.Value)
            Dim dbNewRating As Double = Convert.ToDouble(dbcurrent / 10)
            ''myRating.CurrentRating

            Dim dbFinalRating As Double = dbcurrent + dbNewRating

            If dbFinalRating > 6 Then
                dbFinalRating = dbcurrent
            End If

            Dim b As String = myRating.BehaviorID

            Dim dbconn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("/App_Data/KitchenCompition.mdb"))
            Dim strUpdate As String = "update reciepe set currentrating=" & dbFinalRating & " where Id=" & b.ToString()
            Dim objBl = New BL()
            objBl.GetInsertUpdate(strUpdate, dbconn)
            UpdateRep(False)
           
        Catch ex As Exception

        End Try

          

    End Sub

    Private Sub UpdateRep(full As Boolean)
        Dim objBl = New BL()
        ''Dim objDal = New DL()
        Dim strSelect As String = ""
        rpRecipe.DataSource = ""
        Dim dbconn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Server.MapPath("/App_Data/KitchenCompition.mdb"))
        If (full) Then
            strSelect = "select * from reciepe order by currentrating desc"

            rpRecipe.DataSource = objBl.GetDataAccess(strSelect, dbconn)
            rpRecipe.DataBind()
        Else
            strSelect = "select * from reciepe where Id=" & Request.QueryString("Id").ToString()

            rpRecipe.DataSource = objBl.GetDataAccess(strSelect, dbconn)
            rpRecipe.DataBind()
        End If
        
    End Sub

  

    Protected Sub btnShowAll_Click(sender As Object, e As EventArgs) Handles btnShowAll.Click
        UpdateRep(True)
    End Sub
End Class